package opw;

import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.common.util.HexCodec;
import top.codedance.iotp.iot.sdk.StandandService;
import top.codedance.iotp.iot.sdk.po.sync.ComClientParam;
import top.codedance.iotp.iot.sdk.po.sync.ExecComParam;
import top.codedance.iotp.serialPortSDK.EnterpriseDeviceFactory;
import top.codedance.iotp.serialPortSDK.device.opw.Opw;
import org.junit.Test;

/**
 * @Author 峰
 * @Date 2023/8/24
 * @Description: 测试解析串口数据
 * @Version 1.0
 */
public class TetsAoKe {

    @Test
    public void testParse(){
        StandandService standandService = new StandandService("http://127.0.0.1:10012");
        ExecComParam execComParam = new ExecComParam();
        execComParam.setDeviceId("d1");
        execComParam.setUsername("u1");
        execComParam.setPassword("u1");
        ComClientParam comClientParam = new ComClientParam();
        comClientParam.setId(0);
        Opw aokeOpw = EnterpriseDeviceFactory.getAOKE_OPW();
        HexCodec hc = new HexCodec();
        byte[] bytes = hc.toBytes(aokeOpw.genCmdForHeightOfOil());
        comClientParam.setCommand(bytes);
        execComParam.setClient(comClientParam);
        JSONObject jsonObject = standandService.execCom(execComParam);
        aokeOpw.parse(jsonObject.getJSONObject("data").getString("context"));

        System.out.println("转换完成");
    }

}

